package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.ui.activity.CreditDetailActivity;
import com.cardbaobao.cardbabyclient.ui.activity.LoansDetailActivity;
import com.cardbaobao.cardbabyclient.ui.activity.web.EventWebViewActivity;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerHolder;
import com.cardbaobao.cardbabyclient.base.Constant;
import com.cardbaobao.cardbabyclient.model.IndexLayout;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;

/**
 * Description:
 * Created by FHW
 * on 2017/6/13
 */

public class PopularityRcAdapter extends CommonRecyclerAdapter<IndexLayout.HomeTabBean> {

    public PopularityRcAdapter(Context context) {
        super(context, null, R.layout.item_popularity_rv);
    }

//    @Override
//    public void onClick(View v, int position, CommonRecyclerHolder holder) {
//        ToastUtil.showToast(getmContext(), position + "");
//    }

    @Override
    public void convert(CommonRecyclerHolder holder, final IndexLayout.HomeTabBean homeTabBean) {
        holder.setTextViewText(R.id.tv_title, homeTabBean.getTopical());
        holder.setTextViewText(R.id.tv_marketing_one, homeTabBean.getMarketing_one());
        holder.setTextViewText(R.id.tv_marketing_two, homeTabBean.getMarketing_two());
        holder.setTextViewText(R.id.tv_number, homeTabBean.getNumber());

        ImageView iv_pic = holder.getView(R.id.iv_pic);
        ImageLoaderUtil.displayImage(URLUtil.CBB_IMG_URL + homeTabBean.getPicture_path(), iv_pic, 12);

        ImageView iv_medal = holder.getView(R.id.iv_medal);
        ImageView iv_reason = holder.getView(R.id.iv_reason);
        TextView tv_reason = holder.getView(R.id.tv_reason);

        switch (holder.position) {
            case 0:
                iv_medal.setVisibility(View.VISIBLE);
                iv_medal.setBackgroundResource(R.mipmap.icon_medal_one);
                iv_reason.setVisibility(View.VISIBLE);
                iv_reason.setBackgroundResource(R.mipmap.icon_number_one);
                tv_reason.setTextColor(0xffffe034);
                tv_reason.setText(homeTabBean.getDescription());
                break;
            case 1:
                iv_medal.setVisibility(View.VISIBLE);
                iv_medal.setBackgroundResource(R.mipmap.icon_silver_medal);
                iv_reason.setVisibility(View.VISIBLE);
                iv_reason.setBackgroundResource(R.mipmap.icon_number_two);
                tv_reason.setTextColor(0xffd3e1ea);
                tv_reason.setText(homeTabBean.getDescription());
                break;
            case 2:
                iv_medal.setVisibility(View.VISIBLE);
                iv_medal.setBackgroundResource(R.mipmap.icon_bronze_medal);
                iv_reason.setVisibility(View.VISIBLE);
                iv_reason.setBackgroundResource(R.mipmap.icon_number_three);
                tv_reason.setTextColor(0xffd69982);
                tv_reason.setText(homeTabBean.getDescription());
                break;
            case 3:
                iv_medal.setVisibility(View.VISIBLE);
                iv_medal.setBackgroundResource(R.mipmap.icon_medal_four);
                iv_reason.setVisibility(View.VISIBLE);
                iv_reason.setBackgroundResource(R.mipmap.icon_number_four);
                tv_reason.setTextColor(0xffaaaaaa);
                tv_reason.setText(homeTabBean.getDescription());
                break;
            default:
                iv_medal.setVisibility(View.INVISIBLE);
                iv_reason.setVisibility(View.GONE);
                tv_reason.setVisibility(View.GONE);
                tv_reason.setTextColor(0xffaaaaaa);
                break;
        }

        RelativeLayout rl_item = holder.getView(R.id.rl_item);
        rl_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent();
                switch (homeTabBean.getPage_type()) {
                    case 0://原生页面
                        switch (homeTabBean.getDetail_code()) {
                            case Constant.ZCC0101://信用卡
                                mIntent.setClass(mContext, CreditDetailActivity.class);
                                mIntent.putExtra(CreditDetailActivity.CARD_ID_S,
                                        homeTabBean.getDetail_id());
                                mIntent.putExtra(CreditDetailActivity.SERIES_CARD_ID_S,
                                        homeTabBean.getDetail_id());
                                mIntent.putExtra(CreditDetailActivity.CARD_NAME_S,
                                        homeTabBean.getTopical());
                                mIntent.putExtra(CreditDetailActivity.FROM_PAGE_S,
                                        "首页");
                                mContext.startActivity(mIntent);
                                break;
                            case Constant.ZCC0102://贷款
                                mIntent.setClass(mContext, LoansDetailActivity.class);
                                mIntent.putExtra(LoansDetailActivity.LOANS_ID_S,
                                        homeTabBean.getDetail_id());
                                mIntent.putExtra(LoansDetailActivity.LOANS_NAME_S,
                                        homeTabBean.getTopical());
                                mIntent.putExtra(LoansDetailActivity.FROM_PAGE_S,
                                        "首页");
                                mContext.startActivity(mIntent);
                                break;
                        }
                        break;
                    case 1://H5页面上传
                    case 2://
                        mIntent.setClass(mContext, EventWebViewActivity.class);
                        mIntent.putExtra("url", homeTabBean.getUrl());
                        mIntent.putExtra(EventWebViewActivity.WEB_TITLE_S,homeTabBean.getTopical());
                        mIntent.putExtra(EventWebViewActivity.WEB_TYPE_I,9);
                        mContext.startActivity(mIntent);
                        break;
                }
            }
        });

    }

}
